package game;

import java.awt.*;

/**
 * 炮弹类
 */
public class Shell extends GameObject{
    //炮弹沿着任意角度飞行，核心代码就两行
        //x+= speed*Math.cos(degree);
        //y+= speed*Math.sin(degree);
    double degree;//角度
    public Shell(){
        x = 200;
        y = 200;
        width = 10;
        height = 10;
        speed = 4;

        degree = Math.random()*Math.PI*2;//π=180 ，2π = 360 Math.PI = π
    }
    public void draw(Graphics g){
        Color c = g.getColor();
        g.setColor(Color.YELLOW);

        g.fillOval((int) x,(int) y,width,height);//填充实体
        //炮弹沿着任意角度飞行，核心代码就两行
        x+= speed*Math.cos(degree);
        y+= speed*Math.sin(degree);
        g.setColor(c);//复原

        //判断边界宽高
        if (x > Constant.GAME_WIDH-width || x < 0){
            degree  = Math.PI - degree;
        }
        if (y < 30 || y > Constant.GAME_HEIGHT-height){
            degree = -degree;
        }
    }
}
